package com.lagou.wed.servlet;


import com.alibaba.fastjson.JSON;
import com.lagou.base.BaseServlet;
import com.lagou.pojo.Course;
import com.lagou.service.CourseService;
import com.lagou.service.lmpl.CourseServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/course")
public class CourseSevlet extends BaseServlet {
    public void findCourseList(HttpServletRequest req, HttpServletResponse resp) {
        try {
//            String course_name = req.getParameter("course_name");
//            String status = req.getParameter("status");

            CourseService cs = new CourseServiceImpl();

            List<Course> courseList = cs.findCourseList();

            String s = JSON.toJSONString(courseList);

            resp.getWriter().print(s);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

        public void findCourseNameAndStatus (HttpServletRequest req, HttpServletResponse resp){
            try {


                String course_name = req.getParameter("course_name");
                String status = req.getParameter("status");

                CourseService courseService = new CourseServiceImpl();
                List<Course> result = courseService.findCourseNameAndStatus(course_name, status);
                String s = JSON.toJSONString(result);
                resp.getWriter().print(s);
            } catch (IOException e) {
                e.printStackTrace();
            }


        }
    }

